package com.liangalien.kt.controller;


import com.liangalien.kt.dto.UserDTO;
import com.liangalien.kt.service.UserService;
import com.liangalien.kt.util.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;
//    @Autowired
//    private SysLoginService loginService;

    @RequestMapping(value="/login",method = {RequestMethod.GET,RequestMethod.POST})
    public Response login(@RequestBody Map<String, String> body) {
        // 生成令牌
//        String token = loginService.login(body.get("username"), body.get("password"), body.get("password"), '112233');
//        ajax.put(Constants.TOKEN, token);
//        return ajax;
        return Response.success(userService.login(body.get("username"), body.get("password")));
    }

    @PostMapping("/register")
    public Response register(@RequestBody UserDTO body) {
        userService.register(body);
        return Response.success();
    }
}
